﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using BOL;

using System.Web.UI.DataVisualization.Charting;
using System.Data.SqlClient;
using Website.Logger;
using UtilityExtensions;
using System.Web.UI.HtmlControls;
using System.Drawing;


namespace UILGestion.VentaAdmin.Chart
{
    public partial class Chart04 : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

                if (!this.IsPostBack)
                {

                    idProyecto.Value = (string)Request.QueryString["idProyecto"];
                    FormatForm();
                }
            }
            catch (SqlException sqlex)
            {
                WebServerSideSqlError.Log(sqlex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + sqlex.Message.Replace("'", "") + "');", true);


            }
            catch (Exception ex)
            {
                WebServerSideError.Log(ex);
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page),
                 "uniqueKey" + DateTime.Now, "alert('" + ex.Message.Replace("'", "") + "');", true);

            }
        }

        private void FormatForm()
        {


        }
        public void LoadChart(int idProyecto,int anio,int esAcumulado)
        {


            var proyeccion = new BOL.Ventas.OrdenVentaBL().GetIndicadorNoAcumuladoMes(idProyecto, anio,esAcumulado);

            Chart1.Series[0].ChartArea = "ChartArea1";
            Chart1.Series[1].ChartArea = "ChartArea1";
            Chart1.Series[2].ChartArea = "ChartArea2";
            Chart1.Series[3].ChartArea = "ChartArea2";

            Chart1.Series[0]["LabelStyle"] = "Top";
            Chart1.Series[1]["LabelStyle"] = "Top";
            Chart1.Series[2]["LabelStyle"] = "Top";
            Chart1.Series[3]["LabelStyle"]= "Top";


           

            foreach (var item in proyeccion)
            {
                if (item.mes == 0) { continue; }

                Chart1.Series[0].Points[item.mes-1].YValues[0] = Convert.ToDouble(item.totalSep);
                
                 
                Chart1.Series[1].Points[item.mes-1].YValues[0] = Convert.ToDouble(item.totalVen);
                Chart1.Series[2].Points[item.mes-1].YValues[0] = Convert.ToDouble(item.cantidadSep);
                Chart1.Series[3].Points[item.mes-1].YValues[0] = Convert.ToDouble(item.cantidadVen);
                
            }
            //for (int i = 0; i < 12; i++)
            //{
            //    i++;
            //    //Chart1.Series[1].Points[i].YValues[0] = Convert.ToDouble(proyeccion..totalSep);
            //    //Chart1.Series[0].Points[i].YValues[0] = Convert.ToDouble(item.totalVen);
            //}
            //foreach (var item in proyeccion.Where(p => p.anio == 2014))
            //{
            //    i++;
            //    Chart1.Series[2].Points[i].YValues[0] = Convert.ToDouble(item.totalSep);
            //}



            //Chart1.Series[0].Name = "";
            //Chart1.Titles[0].Text = " Año:{0}".Fmt(anio);


        }
    }
}